<?php
namespace app\admin\model;

use think\Model;
use think\Session;

class User extends Model
{

    public function login($arr)
    {
        $user = $this::get(['username'=>$arr['username'],'password'=>md5($arr['password'])]);
        if ($user){
            Session::set('login',true);
            Session::set('user',$user);
            return true;
        }
        return false;
    }

    static function logout(){
        Session::clear();
    }

    public function user_add($arr)
    {
        $arr['password'] = md5($arr['password']);
        $arr['register_time'] = date("Y-m-d H:i:s");
        $this->data = $arr;
        return $this->save();
    }

    public function getSexAttr($value)
    {
        $sex = [1=>'男',2=>'女',3=>'保密'];
        return $sex[$value];
    }

    
}